package com.heima.wemedia.feign;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AppUserDTO;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author tmh
 * @date 2023/8/28 10:48
 * @description
 */
@RestController
public class IWemediaClientImpl implements IWemediaClient {

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 添加自媒体用户
     * @param appUserDTO
     * @return
     */
    @PostMapping("/api/v1/user/adduser")
    @Override
    public ResponseResult addWemediaUser(@RequestBody AppUserDTO appUserDTO) {
        WmUser wmUser=new WmUser();
        BeanUtils.copyProperties(appUserDTO,wmUser);
        wmUser.setApUserId(appUserDTO.getApUserId());
        wmUser.setCreatedTime(new Date());
        wmUserService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @GetMapping("/api/v1/channel/list")
    @Override
    public ResponseResult getChannels() {
        return wmChannelService.findAll();
    }
}
